package com.yztctech.a24_04_systembroadcast_boot;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * Created by bodhixu on 2016/9/22.
 * 静态注册:接收到系统开机广播后自启动
 * 备注:
 * 1. 开机启动、sd 挂载、低电量、外播电话、锁屏
 */
public class BootReceiver extends BroadcastReceiver{

    @Override
    public void onReceive(Context context, Intent intent) {

        if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
            Log.e("Tag","接收到系统开机广播");
            Intent startIntent = new Intent(context, MainActivity.class);
            startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //注意，必须添加这个标记，否则启动会失败
            context.startActivity(startIntent);
        }

    }

}
